Ext.define('BISC.view.CtxMnuFolderManager', {
    extend: 'Ext.menu.Menu',
    scope: this,
    listeners: {
        click: function( menu, item ) {
            switch( item.identifier ) {
                case 'checkall':
                    this.checkall();
                    break;
                case 'checkallr':
                    this.checkallr();
                    break;
                case 'uncheckall':
                    this.uncheckall();
                    break;
                case 'uncheckallr':
                    this.uncheckallr();
                    break;
            }
        }
    },
    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            items: [
                {
                    text: 'Monitor All',
                    identifier: 'checkall'
                },
                {
                    text: 'Monitor All Recursive',
                    identifier: 'checkallr'
                },
                '-',
                {
                    text: 'Clear All',
                    identifier: 'uncheckall'
                },
                {
                    text: 'Clear All Recursive',
                    identifier: 'uncheckallr'
                }
            ]
        });
        me.callParent(arguments);
    },
    checkall: function() {
        this.record.eachChild( function( child ) {
            child.set( 'checked', true );
            Ext.getCmp('folderManagerWindow').modified[child.data.path] = true;
        });
    },
    checkallr: function() {
        var mask = new Ext.LoadMask(Ext.getCmp('folderManagerTree').getEl(), {msg:'Updating monitors...'});
        mask.show();
        var checkAll = function( node ) {
            node.eachChild( function( child ) {
                child.set( 'checked', true );
                Ext.getCmp('folderManagerWindow').modified[child.data.path] = true;
                checkAll( child );
            });
        }
        this.record.expand( true, function() {
            checkAll( this.record );
            mask.hide();
        }, this);
    },
    uncheckall: function() {
        this.record.eachChild( function( child ) {
            child.set( 'checked', false );
            Ext.getCmp('folderManagerWindow').modified[child.data.path] = false;
        });
    },
    uncheckallr: function() {
        var mask = new Ext.LoadMask(Ext.getCmp('folderManagerTree').getEl(), {msg:'Updating monitors...'});
        mask.show();
        var uncheckAll = function( node ) {
            node.eachChild( function( child ) {
                child.set( 'checked', false );
                Ext.getCmp('folderManagerWindow').modified[child.data.path] = false;
                uncheckAll( child );
            });
        }
        this.record.expand( true, function() {
            uncheckAll( this.record );
            mask.hide();
        }, this);
    }
});
